* This file: ./replication\table_2\table_2_evs.do

* .\replication\table_2\Home_ownership_germany_v2.xlsx
clear
input	year	no	total	job_self	job_civilservant	job_employee	job_worker	job_allemployee	job_unemployed	job_nonemployed	job_retired
	1993	2	35611	.	.	.	.	.	1856	13481	.
	1993	3	16289	.	.	.	.	.	467	5601	.
	1993	4	1975	.	.	.	.	.	63	671	.
	1993	37	8464	.	.	.	.	.	201	1481	.
	1998	1	68863	4807	8113	26156	8308	42577	3159	18320	.
	1998	2	36703	2570	1749	9742	7653	19144	2244	12745	.
	1998	3	16560	1722	1094	4632	3387	9113	620	5106	.
	1998	4	1767	306	110	474	355	939	73	509	.
	1998	37	8910	1118	810	3307	2162	6279	296	1227	.
	2003	1	58309	4062	5913	21177	7376	34466	3177	16604	14781
	2003	2	37931	2684	1621	10780	7043	19444	2261	13541	12356
	2003	3	18514	1894	1114	5524	3365	10003	524	6093	5900
	2003	4	2224	283	132	622	403	1157	62	722	698
	2003	37	10041	1266	826	3909	2160	6895	269	1610	1537
	2008	1	56274	3542	5298	21555	5893	32746	2831	17155	15581
	2008	2	39077	2972	1642	11527	7066	20235	3170	12698	11526
	2008	3	18765	1960	1071	5569	3541	10181	627	5998	5765
	2008	4	1781	276	100	482	299	881	49	575	554
	2008	37	10039	1258	809	3941	2226	6976	262	1542	1453
	2013	1	54949	2512	4955	22043	5013	32011	2191	18235	16347
	2013	2	40032	3134	1526	13625	5945	21096	2041	13760	12211
	2013	3	19015	2055	944	6286	2938	10168	259	6532	6358
	2013	4	1573	245	76	502	224	802	37	512	497
	2013	37	10208	1324	702	4438	1882	7022	114	1747	1699
	2018	1	55711	2295	.	.	.	33358	1746	18312	16393
	2018	2	40596	2866	.	.	.	22363	1859	13507	11904
	2018	3	19290	1879	.	.	.	10677	215	6519	6316
	2018	4	1549	196	.	.	.	851	53.267	481	461
	2018	37	9653	1056	.	.	.	7034	66	1496	1447
end

label define no ///
	1	"Erfasste Haushalte (Anzahl)" ///
	2	"Hochgerechnete Haushalte (1 000)" ///
	3	"Haushalte mit Haus- und Grundbesitz (1 000)" ///
	4	"unbebaute Grundstuecke" ///
	37	"Haushalte mit Restschuld", modify
label val no no
tab no, m

isid year no

rename total job_total
gen job_notunemployed=job_total-job_unemployed

reshape long job_, i(year no) j(status) str

rename job_ v
label list no
reshape wide v, i(year status) j(no)
 
label var v1	"Erfasste Haushalte (Anzahl)"
label var v2	"Hochgerechnete Haushalte (1 000)"
label var v3	"Haushalte mit Haus- und Grundbesitz (1 000)"
label var v4	"unbebaute Grundstuecke"
label var v37	"Haushalte mit Restschuld"

rename v1	respondents
rename v2	N
rename v3	property
rename v4	nohouse
rename v37	debt
gen house=property-nohouse

gen ownership1=(property/N)
gen ownership2=(house/N)
gen mortgage=(debt/N)

label var ownership1 "House or land"
label var ownership2 "House"
label var mortgage "House w/ mortgage"

* UR, from use C:\Dropbox\Rehm\Data\OECD\unemployment_rate\unemployment_rate.dta
preserve
	clear
	input year	UR // YGTT06PC_ST
		1990	 4.82
		1991	 5.57
		1992	 6.62
		1993	 7.87
		1994	 8.40
		1995	 8.13
		1996	 8.86
		1997	 9.82
		1998	 9.20
		1999	 8.41
		2000	 7.76
		2001	 7.84
		2002	 8.65
		2003	 9.64
		2004	 9.79
		2005	11.17
		2006	10.25
		2007	 8.66
		2008	 7.53
		2009	 7.74
		2010	 6.97
		2011	 5.83
		2012	 5.38
		2013	 5.23
		2014	 4.98
		2015	 4.62
		2016	 4.12
		2017	 3.75
		2018	 3.38
		2019	 3.14
	end
	tempfile t
	save `t'
restore
cap drop _merge
merge m:1 year using `t'
drop if _merge==2

encode status, gen(s)

gen post=(year>=2005)
label define post 0 "pre" 1 "post", modify
label val post post

gen emp=1 if status=="notunemployed" // "total"
replace emp=0 if status=="unemployed"

label define emp 1 "Not unempl" 0 "Unempl", modify
label val emp emp


** Difference-in-difference estimates
which diff

*********************************
* Table 2: Homeownership (EVS)
*********************************
diff ownership2, t(emp) p(post)
outreg2 using table_2.xls, ctitle(`r(depvar)') addstat(Mean control t(0), ///
        r(mean_c0), Mean treated t(0), r(mean_t0), Diff t(0), r(diff0), Mean ///
        control t(1), r(mean_c1), Mean treated t(1), r(mean_t1), Diff t(1), ///
        r(diff1)) label excel keep(_diff) nocons
* ^ this is table 2
diff ownership2, t(post) p(emp)
* ^ these are the remaining marginals in table 2


* with controls
local dv ownership2
	ieddtab `dv', time(post) treatment(emp)
	ieddtab `dv', time(post) treatment(emp) covariates(UR)
	ieddtab `dv', time(post) treatment(emp) covariates(i.year)
	ieddtab `dv', time(post) treatment(emp) covariates(c.year)
	ieddtab `dv', time(post) treatment(emp) covariates(UR c.year)


/* sources:
* Employed
new 2018: /Users/rehm.16/Dropbox/Rehm/iversen/credit_markets/data/EVS_Germany/EVS2018_Fachserie15_Heft2.pdf
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\EVS_HausGrundbesitzWohnverhaeltnisHaushalte2018.pdf (p. 23)
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\EVS_2013.pdf
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_2008_HG_12_SOS_D.xls
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_2003_HG_12_ SOS_ D.xls
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_1998_HG_24_SOS_D.pdf
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_1993_HG_HGR_D.pdf
Statistisches Bundesamt, Fachserie 15, Sonderheft 1, EVS 2018, p. 23
Statistisches Bundesamt, Fachserie 15, Sonderheft 1, EVS 2013, p. 22
Statistisches Bundesamt, Fachserie 15, Sonderheft 1, EVS 2008, p. 20

* Unemployed
new 2018: /Users/rehm.16/Dropbox/Rehm/iversen/credit_markets/data/EVS_Germany/EVS2018_Fachserie15_Heft2.pdf

C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\EVS_HausGrundbesitzWohnverhaeltnisHaushalte2018.pdf (p. 23)
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\EVS_2013.pdf (p. 75)
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_2008_HG_12_SOS_D.xls
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_2003_HG_12_ SOS_ D.xls
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_1998_HG_24_SOS_D.pdf
C:\Dropbox\Rehm\iversen\credit_markets\data\EVS_Germany\destatis_email\EVS_1993_HG_21_NET_Arbeitslose_D.pdf
Statistisches Bundesamt, Fachserie 15, Sonderheft 1, EVS 2013, p. 22
Statistisches Bundesamt, Fachserie 15, Sonderheft 1, EVS 2008, p. 20
*/
